package com.sui.bigdata.rtcadmin.repository.mapper;

import com.sui.bigdata.rtcadmin.repository.model.SparkApp;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @Author: TingWuHuang
 * @Date: 2020/5/6 15:30
 * @description
 */
@Mapper
@Component
public interface AppConfMapper {

    @Update("REPLACE INTO spark_app_conf_info (app_name,app_id,app_resource,app_style,main_class,app_status,app_args,developer," +
            "alarm_group_phone,queue,tracking_url, model,executor_memory,driver_memory,executor_cores,num_executors," +
            "extend_param,driver_java_option,executor_java_option,remarks)" +
            "VALUES(#{S.appName},#{S.appId},#{S.appResource},#{S.appStyle},#{S.mainClass},#{S.appStatus},#{S.appArgs},#{S.developer},#{S.alarmGroupPhone}," +
            "#{S.queue},#{S.trackingUrl},#{S.model},#{S.executorMemory},#{S.driverMemory},#{S.executorCores},#{S.numExecutors},#{S.extendParam}," +
            "#{S.driverJavaOption},#{S.executorJavaOption},#{S.remarks})")
    void saveAll(@Param("S") SparkApp sparkApp);

    @Select("<script>"
            + "select * from spark_app_conf_info where 1=1 "
            + "<if test='S.appName != null'>"
            + "and app_name = #{S.appName} "
            + "</if>"
            + "<if test='S.developer != null and S.developer != \"\" '>"
            + "and developer = #{S.developer} "
            + "</if>"
            + "<if test='S.appStatus != null'>"
            + "and app_status = #{S.appStatus} "
            + "</if>"
            + "</script>")
    @ResultType(SparkApp.class)
    List<SparkApp> selectAll(@Param("S") SparkApp sparkApp);

    @Select("select * from spark_app_conf_info where app_name=#{appName}")
    @ResultType(SparkApp.class)
    SparkApp selectByAppName(@Param(value = "appName") String appName);

    @Update("update spark_app_conf_info set app_status=#{appStatus} where app_name=#{appName}")
    void updateStatus(@Param(value = "appName") String appName, @Param(value = "appStatus") String appStatus);

    @Update("update spark_app_conf_info set developer=#{developer}, alarm_group_phone=#{alarmGroupPhone} where app_name=#{appName}")
    void updateBasisConfByName(@Param("appName") String appName, @Param("developer") String developer,
                               @Param("alarmGroupPhone") String alarmGroupPhone);

}
